package kr.co.goodwilldd.service.board.impl;

import java.util.List;

import javax.annotation.PostConstruct;

import kr.co.goodwilldd.entity.board.model.BoardEntity;
import kr.co.goodwilldd.framework.common.model.CommonPaging;
import kr.co.goodwilldd.framework.repository.DefaultRepository;
import kr.co.goodwilldd.repository.board.IBoardRepository;
import kr.co.goodwilldd.service.board.IBoardService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class BoardServiceImpl implements IBoardService {

	@Autowired
	DefaultRepository defaultRepository;

	@Autowired
	IBoardRepository repository;

	@PostConstruct
	@Transactional
	public void init() {
		defaultRepository.doCreateTableBoard();
		defaultRepository.doCreateSequenceBoard();
		defaultRepository.doCreateIndexBoardSeq();
		defaultRepository.doCreateIndexBoardSubject();
		defaultRepository.doCreateUniqueIndexBoard();
	}

	@Override
	public CommonPaging<BoardEntity> getList(Integer boardSeq, Integer cpage,
			String searchKey, String searchValue) {
		CommonPaging<BoardEntity> paging = new CommonPaging<BoardEntity>();
		paging.setCurrentPage(cpage);
		paging.setBoardSeq(boardSeq);
		paging.setList(repository.getList(paging));
		paging.getPagingUtil().setTotalCount(repository.getListCount(paging));
		return paging;
	}
	
	@Override
	public List<BoardEntity> getNoticeList(Integer boardSeq) {
		return repository.getNoticeList(boardSeq);
	}

	@Override
	public BoardEntity getArticle(BoardEntity entity) {
		return repository.getArticle(entity);
	}

	@Override
	@Transactional
	public void doWrite(BoardEntity entity) {
		repository.doWrite(entity);
	}

	@Override
	@Transactional
	public void doDelete(BoardEntity entity) {
		repository.doDelete(entity);
	}

	@Override
	@Transactional
	public void doModify(BoardEntity entity) {
		repository.doModify(entity);
	}

}
